using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Microsoft.Office.Interop.OneNote;
using System.Web;
using System.IO;

namespace InkNotesToOneNote
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.txtInkNote.Text = openFileDialog1.FileName;
            }
        }

        private void btnSaveToOneNote_Click(object sender, EventArgs e)
        {
            if (txtInkNote.Text == "")
                return;

Microsoft.Office.Interop.OneNote.ApplicationClass onApp = new ApplicationClass();
try
{

    //Get the hierarchy for all the notebooks
    //string xmlHierarchy;
    //onApp.GetHierarchy("", HierarchyScope.hsPages, out xmlHierarchy);

    //Get the path for the unfiled notes
    string unfiledNotesPath;
    onApp.GetSpecialLocation(SpecialLocation.slUnfiledNotesSection, out unfiledNotesPath);
    
    //Get the ID of the unfiled notes
    string UnfiledNotesID;
    onApp.OpenHierarchy(unfiledNotesPath, "", out UnfiledNotesID, CreateFileType.cftNone);
    
    //Get the xml of all unfiled notes
    //string xmlUnfiledNotes;
    //onApp.GetHierarchy(UnfiledNotesID, HierarchyScope.hsPages, out xmlUnfiledNotes);

    //Create a new page
    string pageID;
    onApp.CreateNewPage(UnfiledNotesID, out pageID, Microsoft.Office.Interop.OneNote.NewPageStyle.npsBlankPageWithTitle);

    //Read the file data
    StreamReader sr = new StreamReader(txtInkNote.Text);
    string data = sr.ReadToEnd();
    data = string.Format(data, pageID);

    //Add the content to the one note page
    onApp.UpdatePageContent(data, DateTime.MinValue);
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}
        }
    }
}